<?php

namespace Yj\Crontab;

use Hyperf\Di\Annotation\Inject;

class CrontabScheduler
{

    /**
     * @Inject()
     * @var CrontabManager
     */
    private $crontabManager;

    private \SplQueue $schedules;

    public function __construct()
    {
        $this->schedules = new \SplQueue();
    }

    public function schedule(): \SplQueue
    {
        foreach ($this->getSchedules() ?? [] as $schedule) {
            $this->schedules->enqueue($schedule);
        }
        return $this->schedules;
    }

    protected function getSchedules(): array
    {
        return $this->crontabManager->getCrontabList();
    }
}